package com.fr.chart.plot;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.Glyph;
import com.fr.chart.core.TrendLine;
import com.fr.chart.core.glyph.SoloGlyph;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.Graphics;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.util.ArrayList;
import java.util.List;

public class DataSeries extends SoloGlyph
{
  private static final long serialVersionUID = 6421947917220147755L;
  public static final String XML_TAG = "DataSeries";
  private int seriesIndex;
  private String seriesName;
  private List points = new ArrayList();
  private Glyph drawImpl;
  private TrendLine trendLine = null;

  public DataSeries()
  {
  }

  public DataSeries(int paramInt)
  {
    this.seriesIndex = paramInt;
  }

  public int getSeriesIndex()
  {
    return this.seriesIndex;
  }

  public void setSeriesIndex(int paramInt)
  {
    this.seriesIndex = paramInt;
  }

  public void setSeriesName(String paramString)
  {
    this.seriesName = paramString;
  }

  public String getSeriesName()
  {
    return this.seriesName;
  }

  public void setDrawImpl(Glyph paramGlyph)
  {
    this.drawImpl = paramGlyph;
  }

  public Glyph getDrawImpl()
  {
    return this.drawImpl;
  }

  public void addDataPoint(DataPoint paramDataPoint)
  {
    this.points.add(paramDataPoint);
  }

  public int getDataPointCount()
  {
    return this.points.size();
  }

  public DataPoint getDataPoint(int paramInt)
  {
    return ((DataPoint)this.points.get(paramInt));
  }

  public void setTrendLine(TrendLine paramTrendLine)
  {
    this.trendLine = paramTrendLine;
  }

  public TrendLine getTrendLine()
  {
    return this.trendLine;
  }

  public void draw(Graphics paramGraphics)
  {
    if (this.drawImpl != null)
      this.drawImpl.draw(paramGraphics);
    int i = 0;
    int j = getDataPointCount();
    while (i < j)
    {
      getDataPoint(i).draw(paramGraphics);
      ++i;
    }
  }

  public void drawLabel(Graphics paramGraphics)
  {
    int i = 0;
    int j = getDataPointCount();
    while (i < j)
    {
      getDataPoint(i).drawLabel(paramGraphics);
      ++i;
    }
  }

  public void drawTrendLine(Graphics paramGraphics)
  {
    if (this.trendLine != null)
      this.trendLine.draw(paramGraphics);
  }

  public Shape getShape()
  {
    GeneralPath localGeneralPath = new GeneralPath();
    if (this.drawImpl != null)
      localGeneralPath.append(this.drawImpl.getShape(), false);
    int i = 0;
    int j = getDataPointCount();
    while (i < j)
    {
      Shape localShape = getDataPoint(i).getShape();
      if (localShape != null)
        localGeneralPath.append(localShape, false);
      ++i;
    }
    return localGeneralPath;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("DataSeries");
    paramXMLPrintWriter.startTAG("Attr").attr("index", this.seriesIndex).attr("name", this.seriesName).end();
    if ((this.points != null) && (this.points.size() > 0))
    {
      paramXMLPrintWriter.startTAG("DataPoints");
      for (int i = 0; i < this.points.size(); ++i)
        ((DataPoint)this.points.get(i)).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.drawImpl != null)
    {
      paramXMLPrintWriter.startTAG("Glyph");
      this.drawImpl.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("index")) != null)
          setSeriesIndex(Integer.valueOf(str2).intValue());
        if ((str2 = paramXMLableReader.getAttr("name")) != null)
          setSeriesName(str2);
      }
      if (str1.equals("DataPoints"))
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final DataSeries this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              String str = paramXMLableReader.getTagName();
              if (str.equals("DataPoint"))
                DataSeries.access$000(this.this$0).add(paramXMLableReader.readXMLObject(new DataPoint()));
            }
          }
        });
      if (str1.equals("Glyph"))
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final DataSeries this$0;

          public void readXML()
          {
            DataSeries.access$102(this.this$0, ReportXMLUtils.readGlyph(paramXMLableReader));
          }
        });
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof DataSeries))
      return false;
    DataSeries localDataSeries = (DataSeries)paramObject;
    if (localDataSeries.getSeriesIndex() != getSeriesIndex())
      return false;
    if (!(Equals.equals(localDataSeries.getSeriesName(), getSeriesName())))
      return false;
    if (localDataSeries.getDataPointCount() != getDataPointCount())
      return false;
    for (int i = 0; i < localDataSeries.getDataPointCount(); ++i)
      if (!(Equals.equals(localDataSeries.getDataPoint(i), getDataPoint(i))))
        return false;
    return (Equals.equals(localDataSeries.getDrawImpl(), getDrawImpl()));
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if ((this.points != null) && (this.points.size() > 0))
    {
      ArrayList localArrayList = new ArrayList();
      for (int i = 0; i < this.points.size(); ++i)
        localArrayList.add(getDataPoint(i).toJSONObject());
      localJSONObject.put("points", localArrayList);
    }
    return localJSONObject;
  }

  static List access$000(DataSeries paramDataSeries)
  {
    return paramDataSeries.points;
  }

  static Glyph access$102(DataSeries paramDataSeries, Glyph paramGlyph)
  {
    return (paramDataSeries.drawImpl = paramGlyph);
  }
}